package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageBean;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingLevelPageQueryDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Resource
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 查询所有护理等级
     *
     * @return
     */
    @Override
    public List<NursingLevelVo> list() {
        return nursingLevelMapper.getAll();
    }

    /**
     * 新增护理等级
     *
     * @param nursingLevelDto
     */
    @Override
    public void addNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.copyProperties(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.insert(nursingLevel);
    }

    /**
     * 条件分页查询护理等级
     *
     * @param dto
     * @return
     */
    @Override
    public PageBean<NursingLevelVo> listByPage(NursingLevelPageQueryDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        Page<NursingLevel> page = nursingLevelMapper.pageQuery(dto);
        return PageBean.of(page, NursingLevelVo.class);
    }

    /**
     * 根据id查询护理等级
     *
     * @param id
     * @return
     */
    @Override
    public NursingLevelVo getNursingLevelById(Long id) {
        NursingLevel nursingLevel = nursingLevelMapper.getById(id);
        return BeanUtil.copyProperties(nursingLevel, NursingLevelVo.class);
    }

    /**
     * 修改护理等级
     *
     * @param nursingLevelDto
     */
    @Override
    public void updateNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.copyProperties(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(nursingLevel);
    }

    /**
     * 删除护理等级
     *
     * @param id
     */
    @Override
    public void deleteNursingLevel(Long id) {
        nursingLevelMapper.deleteById(id);
    }

    /**
     * 启用禁用护理等级
     *
     * @param id
     * @param status
     */
    @Override
    public void enableOrDisableNursingLevel(Long id, Integer status) {
        NursingLevel nursingLevel = nursingLevelMapper.getById(id);
        nursingLevel.setStatus(status);
        nursingLevelMapper.update(nursingLevel);
    }
}


